package com.ruoyi.lobby.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lobby.domain.Demand;
import com.ruoyi.lobby.service.IDemandService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 机构需求Controller
 * 
 * @author ruoyi
 * @date 2024-11-12
 */
@RestController
@RequestMapping("/lobby/demand")
public class DemandController extends BaseController
{
    @Autowired
    private IDemandService demandService;

    /**
     * 查询机构需求列表
     */
    @PreAuthorize("@ss.hasPermi('lobby:demand:list')")
    @GetMapping("/list")
    public TableDataInfo list(Demand demand)
    {
        startPage();
        List<Demand> list = demandService.selectDemandList(demand);
        return getDataTable(list);
    }

    /**
     * 导出机构需求列表
     */
    @PreAuthorize("@ss.hasPermi('lobby:demand:export')")
    @Log(title = "机构需求", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Demand demand)
    {
        List<Demand> list = demandService.selectDemandList(demand);
        ExcelUtil<Demand> util = new ExcelUtil<Demand>(Demand.class);
        util.exportExcel(response, list, "机构需求数据");
    }

    /**
     * 获取机构需求详细信息
     */
    @PreAuthorize("@ss.hasPermi('lobby:demand:query')")
    @GetMapping(value = "/{reqId}")
    public AjaxResult getInfo(@PathVariable("reqId") Long reqId)
    {
        return success(demandService.selectDemandByReqId(reqId));
    }

    /**
     * 新增机构需求
     */
    @PreAuthorize("@ss.hasPermi('lobby:demand:add')")
    @Log(title = "机构需求", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Demand demand)
    {
        return toAjax(demandService.insertDemand(demand));
    }

    /**
     * 修改机构需求
     */
    @PreAuthorize("@ss.hasPermi('lobby:demand:edit')")
    @Log(title = "机构需求", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Demand demand)
    {
        return toAjax(demandService.updateDemand(demand));
    }

    /**
     * 删除机构需求
     */
    @PreAuthorize("@ss.hasPermi('lobby:demand:remove')")
    @Log(title = "机构需求", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reqIds}")
    public AjaxResult remove(@PathVariable Long[] reqIds)
    {
        return toAjax(demandService.deleteDemandByReqIds(reqIds));
    }
}
